package com.dgut.doctorservice.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dgut.commonutils.Result;
import com.dgut.doctorservice.entity.Doctor;
import com.dgut.doctorservice.service.DoctorService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/doctorservice/doctor")
@CrossOrigin//解决跨域问题
public class DoctorLoginController {

    @Autowired
    DoctorService doctorService;

    //login
    @ApiOperation("医生进行登录")
    @PostMapping("login")
    public Result login(@RequestParam String phone,@RequestParam String password){

        QueryWrapper<Doctor> wrapper = new QueryWrapper<>();
        wrapper.eq("phone",phone);
        Doctor one = doctorService.getOne(wrapper);
        if (one==null){
            return Result.fail().message("未存在账户");
        }else {
            if (one.getPassword().equals(password)){
                one.setPassword(null);
                return Result.succ().data("doctor",one);
            }else {
                return Result.fail().message("密码错误");
            }
        }
//        return Result.succ().data("token","admin");
    }

    //info
    @GetMapping("info")
    public Result info(){
        return Result.succ().data("name","admin").data("avatar","https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif");
    }

}
